<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>This function returns an array of messages matching the given search criteria</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.imap-scanmailbox.html">« imap_scanmailbox</a></li>
      <li style="float: right;"><a href="function.imap-set-quota.html">imap_set_quota »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.imap.html">IMAP 函数</a></li>
    <li>This function returns an array of messages matching the given search criteria</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.imap-search" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imap_search</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imap_search</span> &mdash; <span class="dc-title">This function returns an array of messages matching the given search criteria</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imap-search-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imap_search</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type IMAP\Connection">IMAP\Connection</span></span> <code class="parameter">$imap</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$criteria</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code>SE_FREE</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$charset</code><span class="initializer"> = &quot;&quot;</span></span><br>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   This function performs a search on the mailbox currently opened
   in the given <abbr title="Internet Message Access Protocol">IMAP</abbr> stream. 
  </p>
  <p class="para">
   For example, to match all unanswered messages sent by Mom, you&#039;d
   use: &quot;UNANSWERED FROM mom&quot;. Searches appear to be case
   insensitive. This list of criteria is from a reading of the UW
   c-client source code and may be incomplete or
   inaccurate (see also <a href="http://www.faqs.org/rfcs/rfc1176" class="link external">&raquo;&nbsp;RFC1176</a>, 
   section &quot;tag SEARCH search_criteria&quot;).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imap-search-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    <dt>

<code class="parameter">imap</code></dt>
<dd>
<p class="para"><span class="classname"><strong class="classname">IMAP\Connection</strong></span> 实例。</p></dd>

    
     <dt>
<code class="parameter">criteria</code></dt>

     <dd>

      <p class="para">
       A string, delimited by spaces, in which the following keywords are
       allowed. Any multi-word arguments (e.g.
       <code class="literal">FROM &quot;joey smith&quot;</code>) must be quoted. Results will match
       all <code class="parameter">criteria</code> entries.
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          ALL - return all messages matching the rest of the criteria
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          ANSWERED - match messages with the \\ANSWERED flag set
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          BCC &quot;string&quot; - match messages with &quot;string&quot; in the Bcc: field
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          BEFORE &quot;date&quot; - match messages with Date: before &quot;date&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          BODY &quot;string&quot; - match messages with &quot;string&quot; in the body of the message
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          CC &quot;string&quot; - match messages with &quot;string&quot; in the Cc: field
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          DELETED - match deleted messages
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          FLAGGED - match messages with the \\FLAGGED (sometimes
          referred to as Important or Urgent) flag set
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          FROM &quot;string&quot; - match messages with &quot;string&quot; in the From: field
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          KEYWORD &quot;string&quot; - match messages with &quot;string&quot; as a keyword
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          NEW - match new messages
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          OLD - match old messages
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          ON &quot;date&quot; - match messages with Date: matching &quot;date&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          RECENT - match messages with the \\RECENT flag set
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          SEEN - match messages that have been read (the \\SEEN flag is set)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          SINCE &quot;date&quot; - match messages with Date: after &quot;date&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          SUBJECT &quot;string&quot; - match messages with &quot;string&quot; in the Subject:
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          TEXT &quot;string&quot; - match messages with text &quot;string&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          TO &quot;string&quot; - match messages with &quot;string&quot; in the To:
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNANSWERED - match messages that have not been answered
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNDELETED - match messages that are not deleted
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNFLAGGED - match messages that are not flagged
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNKEYWORD &quot;string&quot; - match messages that do not have the
          keyword &quot;string&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNSEEN - match messages which have not been read yet
         </span>
        </li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       Valid values for <code class="parameter">flags</code> are 
       <strong><code>SE_UID</code></strong>, which causes the returned array to
       contain UIDs instead of messages sequence numbers.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">charset</code></dt>

     <dd>

      <p class="para">
       MIME character set to use when searching strings.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imap-search-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an array of message numbers or UIDs.
  </p>
  <p class="para">
   Return <strong><code>false</code></strong> if it does not understand the search
   <code class="parameter">criteria</code> or no messages have been found.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.imap-search-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">imap</code> 参数接受 <span class="classname"><strong class="classname">IMAP\Connection</strong></span>
  实例，之前接受 <a href="language.types.resource.html" class="link">资源(resource)</a>。
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imap-search-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="imap-search.examples">
   <p><strong>示例 #1 <span class="function"><strong>imap_search()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$imap&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'{imap.example.com:993/imap/ssl}INBOX'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'foo@example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'pass123'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">OP_READONLY</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$some&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$imap</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SUBJECT&nbsp;"HOWTO&nbsp;be&nbsp;Awesome"&nbsp;SINCE&nbsp;"8&nbsp;August&nbsp;2008"'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SE_UID</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$msgnos&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$imap</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ALL'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$uids&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$imap</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ALL'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SE_UID</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$some</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnos</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$uids</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; 4
    [1] =&gt; 6
    [2] =&gt; 11
)
Array
(
    [0] =&gt; 1
    [1] =&gt; 2
    [2] =&gt; 3
    [3] =&gt; 4
    [4] =&gt; 5
    [5] =&gt; 6
)
Array
(
    [0] =&gt; 1
    [1] =&gt; 4
    [2] =&gt; 6
    [3] =&gt; 8
    [4] =&gt; 11
    [5] =&gt; 12
)
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.imap-search-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.imap-listscan.html" class="function" rel="rdfs-seeAlso">imap_listscan()</a> - Returns the list of mailboxes that matches the given text</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>